package jp.example.sinya.fragment.manage.utils;

import android.os.Bundle;

import jp.example.sinya.fragment.manage.constants.FragmentConstants;
import jp.example.sinya.fragment.manage.fragment.MainFragment;
import jp.example.sinya.fragment.manage.OnChangeFragmentListener;
import jp.example.sinya.fragment.manage.fragment.BaseFragment;
import jp.example.sinya.fragment.manage.fragment.BlankFragment1;
import jp.example.sinya.fragment.manage.fragment.BlankFragment2;
import jp.example.sinya.fragment.manage.fragment.BlankFragment3;
import jp.example.sinya.fragment.manage.fragment.BlankFragment4;
import jp.example.sinya.fragment.manage.fragment.BlankFragment5;
import jp.example.sinya.fragment.manage.fragment.BlankFragment6;
import jp.example.sinya.fragment.manage.fragment.OtherFragment;

/**
 * @author Sinya
 * @editor
 * @date 23/4/2018 7:34 PM
 * @describe
 */
public class FragmentUtils {

    public static BaseFragment getFragment(OnChangeFragmentListener listener, Bundle bundle, int fragmentIndex) {

        BaseFragment fragment;

        if (bundle == null) {
            bundle = new Bundle();
        }

        if (fragmentIndex > 7) {
            fragmentIndex = fragmentIndex % 7;
            if (fragmentIndex == 0) {
                fragmentIndex = 7;
            }

        }

        switch (fragmentIndex) {
            case FragmentConstants.FRAGMENT_1:
                fragment = new BlankFragment1();
                break;
            case FragmentConstants.FRAGMENT_2:
                fragment = new BlankFragment2();
                break;
            case FragmentConstants.FRAGMENT_3:
                fragment = new BlankFragment3();
                break;
            case FragmentConstants.FRAGMENT_4:
                fragment = new BlankFragment4();
                break;
            case FragmentConstants.FRAGMENT_5:
                fragment = new BlankFragment5();
                break;
            case FragmentConstants.FRAGMENT_6:
                fragment = new BlankFragment6();
                break;

            case FragmentConstants.FRAGMENT_OTHER:
                fragment = new OtherFragment();
                break;

            default:
                fragment = new MainFragment();
                break;
        }

        if (listener != null) {
            fragment.setOnChangeFragmentListener(listener);
        }

        fragment.setArguments(bundle);

        return fragment;
    }
}
